package com.mathpractise.question.generator;

import com.mathpractise.model.Question;
import com.mathpractise.model.TrainingConfig;
import com.mathpractise.model.enums.QuestionType;
import com.mathpractise.util.RandomUtil;
import org.springframework.stereotype.Component;

/**
 * 1位数加法题目生成器
 */
@Component
public class OneDigitAdditionGenerator extends AbstractQuestionGenerator {
    
    @Override
    public QuestionType getSupportedType() {
        return QuestionType.ONE_DIGIT_ADDITION;
    }
    
    @Override
    protected Question doGenerateQuestion(TrainingConfig trainingConfig) {
        int num1, num2;
        
        // 确保不会生成 n+0 或 0+n 的题目
        do {
            // 生成两个1位数（1-9）
            num1 = RandomUtil.nextInt(1, 10);
            num2 = RandomUtil.nextInt(1, 10);
        } while (num1 == 0 || num2 == 0); // 额外检查确保不为0
        
        String expression = num1 + "+" + num2;
        int correctAnswer = num1 + num2;
        
        Question question = new Question();
        question.setExpression(expression);
        question.setCorrectAnswer(correctAnswer);
        
        return question;
    }
}